package com.meepo.framework.design.viewpager.adapter;

import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import java.util.ArrayList;
import java.util.List;

public class DefaultFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
    private final List<Fragment> fragments;
    private final String[] names;


    public DefaultFragmentStatePagerAdapter(FragmentManager fm, List<Fragment> fragments, String[] names) {
        super(fm);
        this.fragments = fragments;
        this.names = names;
    }

    public DefaultFragmentStatePagerAdapter(FragmentManager fm, List<Fragment> fragments) {
        this(fm, fragments, null);
    }


    @NonNull
    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }


    @Override
    public CharSequence getPageTitle(int position) {
        if (names != null) {
            return names[position];
        } else {
            return "";
        }
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
//        super.destroyItem(container, position, object);
    }
}
